home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_12_1986_Transactor_Publishing.d64 / func wedge.pal (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  10KB  |  365 lines

  1. 1000 ;
  2. 1010 ;function wedge
  3. 1020 ;by frank e. digioia
  4. 1030 ;11/12/85
  5. 1040 ;
  6. 1050 * = $c000       ;convenient start
  7. 1060 ;
  8. 1070 chrget = $0073         ;get byte of text
  9. 1080 chr(NULL)t = $0079         ;get same byte
  10. 1090 ieval  = $030a         ;evaluation vector
  11. 1100 type   = $0d           ;type flag
  12. 1110 ;
  13. 1120 init   = *             ;initialize routine
  14. 1130 lda #<fwedge
  15. 1140 sta ieval
  16. 1150 lda #>fwedge
  17. 1160 sta ieval+1
  18. 1170 rts
  19. 1180 ;
  20. 1190 fwedge = *             ;this is the wedge
  21. 1200 lda #$00        ;flag for numeric
  22. 1210 sta type        ;set type flag
  23. 1220 ;
  24. 1230 jsr chrget      ;see what we've (NULL)t
  25. 1240 cmp #'$'        ;hex conversionprint
  26. 1250 beq jump
  27. 1260 cmp #'%'        ;binary conversionprint
  28. 1270 beq jump+3
  29. 1280 cmp #'@'        ;plot functionprint
  30. 1290 beq jump+6
  31. 1300 cmp #'#'        ;the # commandprint
  32. 1310 beq jump+9
  33. 1320 cmp #'!'        ;use the parserprint
  34. 1330 beq parser
  35. 1340 ;not one of ours
  36. 1350 jsr chr(NULL)t      ;set flags again
  37. 1360 jmp $ae8d       ;use original routine
  38. 1370 ;
  39. 1380 jump   = *             ;jump table for fns
  40. 1390 jmp hex
  41. 1400 jmp bin
  42. 1410 jmp xplot
  43. 1420 jmp expand
  44. 1430 ;
  45. 1440 parser = *             ;parse & execute
  46. 1450 lda #$00        ;clear all regs
  47. 1460 sta count       ;and counter
  48. 1470 tax
  49. 1480 tay
  50. 1490 ;
  51. 1500 ploop  iny             ;incr text index
  52. 1510 lda table,x     ;get table byte
  53. 1520 beq error       ;end of table
  54. 1530 inx             ;incr table pointer
  55. 1540 cmp ($7a),y     ;cmpare with text
  56. 1550 bne next        ;find next word
  57. 1560 beq ploop       ;match/keep looking
  58. 1570 ;
  59. 1580 next   dex             ;bump .x down once
  60. 1590 lda table,x     ;end of table wordprint
  61. 1600 bpl find        ;no/find end of word
  62. 1610 and #$7f        ;yes/mask flag
  63. 1620 cmp ($7a),y     ;is it a matchprint
  64. 1630 beq found       ;hooray!!!
  65. 1640 bne x1          ;(NULL) back for more
  66. 1650 ;
  67. 1660 find   inx             ;find end of word
  68. 1670 lda table,x     ;look for negative
  69. 1680 beq error       ;end of table
  70. 1690 bpl find        ;keep looking
  71. 1700 ;
  72. 1710 x1     inx             ;point to next word
  73. 1720 inc count       ;word # in table
  74. 1730 ldy #$00        ;reset text index
  75. 1740 jmp ploop       ;search some more
  76. 1750 ;
  77. 1760 found  = *             ;execution routine
  78. 1770 iny             ;point to next byte
  79. 1780 tya             ;update text pointer
  80. 1790 clc
  81. 1800 adc $7a
  82. 1810 sta $7a
  83. 1820 bcc *+4
  84. 1830 inc $7b
  85. 1840 ;
  86. 1850 lda count       ;get offset in table
  87. 1860 asl a           ;multiply by two
  88. 1870 tax             ;use as index
  89. 1880 lda adrtab+1,x  ;hi byte adr
  90. 1890 pha             ;as return adr hi
  91. 1900 lda adrtab,x    ;lo byte adr
  92. 1910 pha             ;as return adr lo
  93. 1920 rts             ;execute routine
  94. 1930 ;
  95. 1940 count  .byte $00
  96. 1950 error  jmp $af08       ;syntax error
  97. 1960 ;
  98. 1970 ;data tables -- add your own
  99. 1980 ;routine names and addresses
  100. 1990 ;here. be sure to add $80 to
  101. 2000 ;last character of name and
  102. 2010 ;subtract 1 from the address
  103. 2020 ;
  104. 2030 table  .byte 'mo',$c4,'fra',$c3
  105. 2040 .byte  'di',$d6,'dsta',$d4,$00
  106. 2050 ;
  107. 2060 adrtab .word mod-1,frac-1,div-1,dstat-1
  108. 2070 ;
  109. 2080 ;
  110. 2090 ;function calculation routines
  111. 2100 ;
  112. 2110 ;dstat function
  113. 2120 ;
  114. 2130 acptr  = $ffa5         ;get byte from serial port
  115. 2140 fa     = $ba           ;device number
  116. 2150 sa     = $b9           ;secondary address
  117. 2160 wbuf   = $033c         ;buffer for string
  118. 2170 talk   = $ffb4         ;tell device to talk
  119. 2180 tksa   = $ff96         ;send 2nd adr for talk
  120. 2190 untalk = $ffab         ;free serial bus
  121. 2200 ;
  122. 2210 dstat  = *
  123. 2220 ldx #$08        ;device number (disk)
  124. 2230 stx fa          ;first address
  125. 2240 txa
  126. 2250 jsr talk        ;tell drive to speak
  127. 2260 lda #$6f        ;channel 15 (or $60)
  128. 2270 sta sa          ;secondary address
  129. 2280 jsr tksa        ;send it to drive
  130. 2290 ldx #$00
  131. 2300 ;
  132. 2310 dloop  = *             ;read command channel
  133. 2320 jsr acptr       ;get byte from drive
  134. 2330 sta wbuf,x      ;store character
  135. 2340 inx
  136. 2350 cmp #$0d        ;carriage returnprint
  137. 2360 bne dloop
  138. 2370 jsr untalk      ;free serial port
  139. 2380 ;
  140. 2390 dex             ;forget the <cr>
  141. 2400 txa             ;put length in .a
  142. 2410 sta len         ;save it
  143. 2420 jsr $b47d       ;reserve space for string
  144. 2430 ldy len         ;use length for index
  145. 2440 ;
  146. 2450 dloop2 = *             ;copy string for basic
  147. 2460 lda wbuf,y      ;get byte of string
  148. 2470 sta ($62),y     ;put in string mem.
  149. 2480 dey             ;bump pointer down
  150. 2490 bpl dloop2
  151. 2500 jmp $b4ca       ;put dscrptr on stack
  152. 2510 ;
  153. 2520 ;
  154. 2530 ;@(row,col) function - plot
  155. 2540 ;cursor and return null string
  156. 2550 ;
  157. 2560 chklft = $aefa         ;check left paren
  158. 2570 chkrht = $aef7         ;check right paren
  159. 2580 chkcom = $aefd         ;check on comma
  160. 2590 getbyt = $b79e         ;get byte into .x
  161. 2600 plot   = $fff0         ;plot/fetch cursor
  162. 2610 ;
  163. 2620 xplot  = *
  164. 2630 jsr chrget      ;get next byte
  165. 2640 jsr getprm      ;get row/col in x/y
  166. 2650 cpx #$19        ;row less than 25print
  167. 2660 bcc chky        ;yes/check column
  168. 2670 bad    jmp ilegal      ;no/illegal quant.
  169. 2680 chky   cpy #$28        ;col less than 40print
  170. 2690 bcs bad         ;no/trash it.
  171. 2700 clc             ;just for looks
  172. 2710 jsr plot        ;plot the cursor
  173. 2720 lda #$00        ;set len to zero
  174. 2730 jsr $b47d       ;reserve space
  175. 2740 jmp $b4ca       ;put descrptr on stack
  176. 2750 ;
  177. 2760 getprm=*;get (a,b) into .x/.y
  178. 2770 jsr chklft      ;check open paren
  179. 2780 jsr getbyt      ;get first parm
  180. 2790 stx len         ;save it here
  181. 2800 jsr chkcom      ;check on comma
  182. 2810 jsr getbyt      ;get second byte
  183. 2820 txa             ;put in .a
  184. 2830 pha             ;keep it safe
  185. 2840 jsr chkrht      ;check closing paren
  186. 2850 pla             ;retrieve 2nd parm
  187. 2860 tay             ;put in .y
  188. 2870 ldx len         ;retrieve 1st parm
  189. 2880 rts
  190. 2890 len    .byte $00
  191. 2900 ;
  192. 2910 ;
  193. 2920 ;the #(lo,hi) command -- convert
  194. 2930 ;lo/hi to 16 bit number.
  195. 2940 ;
  196. 2950 expand = *
  197. 2960 jsr chrget      ;get next byte of text
  198. 2970 jsr getprm      ;get parms into x/y
  199. 2980 stx $63         ;lo byte in $63
  200. 2990 sty $62         ;hi byte in $62
  201. 3000 ldx #$90        ;set exponent to 15
  202. 3010 sec             ;don't invert mantissa
  203. 3020 jmp $bc49       ;convert to fac
  204. 3030 ;
  205. 3040 ;
  206. 3050 ;hex/binary conversion routine --
  207. 3060 ;this routine converts ascii
  208. 3070 ;hex or binary numbers to floating
  209. 3080 ;point.
  210. 3090 ;
  211. 3100 addbyt = $bd7e         ;add .a to fac
  212. 3110 ilegal = $b248         ;illegal quantity
  213. 3120 oflow  = $b97e         ;overflow error
  214. 3130 exp    = $61           ;exponent of fac
  215. 3140 ;
  216. 3150 hex    lda #$00        ;flag for hex
  217. 3160 .byte $2c       ;skip next instr.
  218. 3170 bin    lda #$01        ;flag for binary
  219. 3180 sta flag        ;save flag
  220. 3190 jsr zero        ;set fac to zero
  221. 3200 ;
  222. 3210 loop   jsr chrget      ;get next char.
  223. 3220 beq cdone       ;end of statement
  224. 3230 jsr convrt      ;convert from ascii
  225. 3240 jsr incexp      ;incr. fac exponent
  226. 3250 jsr addbyt      ;add the byte to fac
  227. 3260 jmp loop
  228. 3270 ;
  229. 3280 quit   pla             ;pull return adr.
  230. 3290 pla
  231. 3300 cdone  jmp chr(NULL)t      ;set flags & rts
  232. 3310 ;
  233. 3320 ;hex/bin subroutines
  234. 3330 ;
  235. 3340 zero   = *             ;set fac to zero
  236. 3350 lda #$00        ;here's the zero
  237. 3360 ldx #$05        ;5 bytes + sign
  238. 3370 ;
  239. 3380 zilch  sta exp,x       ;zero out byte
  240. 3390 dex             ;bump index down
  241. 3400 bpl zilch       ;counter roll overprint
  242. 3410 rts
  243. 3420 ;
  244. 3430 convrt = *             ;ascii digit to true value
  245. 3440 bcc digit       ;chrget flag/digitprint
  246. 3450 ldx flag        ;hex or binaryprint
  247. 3460 bne chkerr      ;binary non-digit
  248. 3470 cmp #'a'        ;check lower limit
  249. 3480 bcc quit        ;less than 'a'
  250. 3490 cmp #'g'        ;check upper limit
  251. 3500 bcs chkerr      ;bigger than 'f'
  252. 3510 sec
  253. 3520 sbc #$07        ;account for extra 7
  254. 3530 digit  ldx flag        ;hex or binaryprint
  255. 3540 beq okay        ;hex/any digit is fine
  256. 3550 cmp #'2'        ;bin/check upper limit
  257. 3560 bcs err2        ;bigger than 1
  258. 3570 okay   sec
  259. 3580 sbc #$30        ;convert to true value
  260. 3590 rts
  261. 3600 ;
  262. 3610 chkerr = *             ;check illegal quant.
  263. 3620 cmp #$41        ;compare with 'a'
  264. 3630 bcc quit        ;less than 'a'
  265. 3640 cmp #$5b        ;compare with '['
  266. 3650 bcs quit        ;greater than 'z'
  267. 3660 err2   jmp ilegal      ;illegal quantity
  268. 3670 ;
  269. 3680 ;
  270. 3690 incexp =  *            ;increment exponent
  271. 3700 ldx exp         ;get exponent
  272. 3710 beq exit        ;fac=0, don't incr.
  273. 3720 pha             ;save byte in .a
  274. 3730 ldx flag        ;use flag for offset
  275. 3740 lda incr,x      ;get incr in .a
  276. 3750 clc
  277. 3760 adc exp         ;add exp to incr.
  278. 3770 bcs err1        ;overflow error
  279. 3780 sta exp         ;update exponent
  280. 3790 pla             ;retrieve byte to .a
  281. 3800 exit   rts
  282. 3810 ;
  283. 3820 err1   jmp oflow
  284. 3830 incr   .byte $04,$01
  285. 3840 flag   .byte $00
  286. 3850 ;
  287. 3860 ;
  288. 3870 ;div/mod/frac -- these routines respectively
  289. 3880 ;return the integer-quotient,
  290. 3890 ;integer-remainder, or fractional
  291. 3900 ;part of the quotient a/b.
  292. 3910 ;
  293. 3920 exp    = $61           ;adr of exp of fac
  294. 3930 facarg = $bc0c         ;copy fac to arg
  295. 3940 facmem = $bbd4         ;store fac at adr in (x/y)
  296. 3950 mdiv   = $bb0f         ;divide fac by mem
  297. 3960 subtrt = $b853         ;subtract fac from arg
  298. 3970 mmult  = $ba28         ;mult fac by mem (a/y)
  299. 3980 facint = $bccc         ;convert fac to integer
  300. 3990 round  = $bc1b         ;round the fac
  301. 4000 add5   = $b849         ;add .5 to fac
  302. 4010 frmnum = $ad8a         ;get numeric parm into fac
  303. 4020 ;
  304. 4030 ;
  305. 4040 div    = *             ;entry for div
  306. 4050 lda #$00        ;flag for div
  307. 4060 .byte $2c       ;skip next instr
  308. 4070 mod    = *             ;entry for mod
  309. 4080 lda #$01        ;flag for mod
  310. 4090 .byte $2c       ;skip next instr
  311. 4100 frac   = *             ;entry for frac
  312. 4110 lda #$ff        ;flag for frac
  313. 4120 sta flag        ;set the flag
  314. 4130 ;
  315. 4140 ;get first parm in fac and 2nd
  316. 4150 ;parm in arg.
  317. 4160 ;
  318. 4170 jsr chklft      ;open parenprint
  319. 4180 jsr frmnum      ;get first value
  320. 4190 ldx #<temp      ;lo byte of address
  321. 4200 ldy #>temp      ;hi byte of address
  322. 4210 jsr facmem      ;place in temp
  323. 4220 jsr chkcom      ;commaprint
  324. 4230 jsr frmnum      ;get 2nd parm
  325. 4240 jsr chkrht      ;closing parenprint
  326. 4250 ;
  327. 4260 ldx #<modlus    ;get adr of modlus
  328. 4270 ldy #>modlus    ;in .x/.y
  329. 4280 jsr facmem      ;store fac at modlus
  330. 4290 ;
  331. 4300 lda #<temp      ;adr of 1st parm (lo)
  332. 4310 ldy #>temp      ;adr of 1st parm (hi)
  333. 4320 jsr mdiv        ;fac = temp/fac
  334. 4330 jsr facarg      ;arg = fac
  335. 4340 jsr facint      ;fac = int(fac)
  336. 4350 ;
  337. 4360 ;check flag.  if div function
  338. 4370 ;then done, else continue.
  339. 4380 ;
  340. 4390 lda flag
  341. 4400 beq done
  342. 4410 ;
  343. 4420 lda exp         ;must have exp in .a
  344. 4430 jsr subtrt      ;fac = arg - fac
  345. 4440 ;
  346. 4450 ;check flag.  if frac function
  347. 4460 ;then done, else continue.
  348. 4470 ;
  349. 4480 lda flag
  350. 4490 bmi done
  351. 4500 ;
  352. 4510 lda #<modlus    ;get address of the
  353. 4520 ldy #>modlus    ;modulus in .a/.y
  354. 4530 jsr mmult       ;fac = fac * modlus
  355. 4540 jsr add5        ;add .5 for roundoff
  356. 4550 jsr facint      ;truncate garbage
  357. 4560 ;
  358. 4570 done   jsr round       ;round the fac
  359. 4580 rts
  360. 4590 ;
  361. 4600 modlus * = *+5
  362. 4610 temp   * = *+5
  363. 4620 ;
  364. 4630 .end
  365.